package list;

import java.util.Random;
import java.util.Vector;

public class VectorTest {

	static volatile boolean isStop;
	
	public static void main(String[] args) throws InterruptedException {
		
//		List<String> str = new ArrayList<>();
//		List<String> str = new CopyOnWriteArrayList<>();
		Vector<String> str = new Vector<>();
		Thread t1 = new Thread(){
			public void run() {
				for(int i = 0; i < 10000; i++){
					str.add(String.valueOf(i));
				}
				isStop = true;
			};
		};
		Thread t2 = new Thread(){
			public void run() {
				while(!isStop){
					while(str.size() > 0){
						synchronized (str) {
							str.remove(new Random().nextInt(str.size()));
						}
					}
				}
			};
		};
		t1.start();
		t2.start();
		t1.join();
		t2.join();
		System.out.println(str.size());
	}
}
